package com.tianji.learning.mapper;

import com.tianji.learning.domain.po.PointsRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 学习积分记录，每个月底清零 Mapper 接口
 * </p>
 *
 * @author WangXinyi
 * @since 2025-01-11
 */
public interface PointsRecordMapper extends BaseMapper<PointsRecord> {


    /**
     * 获取当天的积分数量
     *
     * @param userId
     * @param type
     * @param atStartOfDay
     * @param atedTime
     * @return
     */
    Integer getDayPonits(Long userId, int type, LocalDateTime atStartOfDay, LocalDateTime atedTime);

    @Select("select sum(points) as points,type from tj_learning.points_record where user_id = #{userId} and now() between #{atStartOfDay} and #{atedTime}  group by type")
    List<PointsRecord> queryMyPointsToday(Long userId, LocalDateTime atStartOfDay, LocalDateTime atedTime);
}
